<template>
<a-card :bordered="false">
   <a-layout >
      <a-layout-sider theme="light" :style="{ overflow: 'auto', height: '60vh' }">
        <a-tree :tree-data="treeData" :replaceFields="replaceFields" @select="onSelect"/>
     </a-layout-sider>
      <a-layout-content style="background: #fff;" v-if="currentClickSystem">
        <a-spin :spinning="spinning">
  
              
             <div class="table-operator">
                <a-button shape="round" size="small" type="primary" icon="plus" @click="addMenu">新增</a-button>
            </div>
            <LTable
                ref="menuList"
                size="middle"
                rowKey="keyId"
                :columns="columns"
                :initQuery="initQuery"
                axiosUrl="/SysMenuController/queryMenuTableTree"
                :showPagination="false"
                :showQueryForm="false"
                :isAutoLoad="false"
            >
                <span slot="action" slot-scope="text, record">
                    <a @click="handleEdit(record,'menuForm',record.menuTitle)">编辑</a>
                    <a-divider type="vertical" />
                    <a @click="handleEdit(record,'menuButtonList',record.menuTitle)"><a-icon type="setting" />按钮设置</a>
                    <a-divider type="vertical" />
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete({keyId:record.keyId},'/SysMenuController/del','menuList')">
                        <a>删除</a>
                    </a-popconfirm>
                   
                </span>
                
            </LTable>
            <menuForm ref="menuForm" @close="refresh('menuList')" @ok="refresh('menuList')"></menuForm> 
            <menuButtonList ref="menuButtonList"></menuButtonList>
              
    
        </a-spin>
        
      </a-layout-content>
  
    </a-layout>
    
</a-card>
    
</template>

<script>
import LTable from '@/components/lt/LTable'
import menuForm from './menuForm'
import menuButtonList from './menuButtonList'
import {SysMixin} from '@/mixins/SysMixin'
import {getSystemInfo} from '@/api/system'
export default {
    name:'menuList',
    components: {
        LTable,
        menuForm,
        menuButtonList
    },
    mixins:[SysMixin],
    data(){
        return{
            replaceFields:{title:'systemName',vlaue:'systemNo',key:'systemNo'},
            treeData:[],
            visible:false,
            spinning:false,
            currentClickSystem:'',
            initQuery:[],
            columns:[
                {
                    title: '标题',
                    dataIndex: 'menuTitle'
                },
                {
                    title: '路径',
                    dataIndex: 'menuPath', 
                },
                {
                    title: '组件',
                    dataIndex: 'menuComponent'
                },
              
                {
                    title: '模块',
                    dataIndex: 'systemNo',
                    
                },
                
                {
                    title: '操作',
                    dataIndex: 'action',
                    width: '220px',
                    scopedSlots: { customRender: 'action' }
                }
            ]

        }
    },
    methods:{
        //获取系统信息
        getSystemInfo(){
            let that = this;
            getSystemInfo().then(res => {
                if(res.success && res.result){
                    that.treeData = res.result
                }
            })
        },
        onSelect(selectedKeys, info){
            let that = this;
            that.visible=true;
            that.currentClickSystem= info.node.eventKey
            that.initQuery=[{field:'systemNo',val:this.currentClickSystem}]
             this.$nextTick(() => {
                 that.$refs["menuList"].searchQuery()
            })
           
        },
        addMenu(){
            if(!this.currentClickSystem){
                that.$message.warning("请先选择模块");
            }
            this.handleEdit({systemNo:this.currentClickSystem},'menuForm','新增')
        }
    },
    created(){
        //加载数据
        this.getSystemInfo();
    },
    
}
</script>